package com.ruoyi.common.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;


@Data
public class UserEntity implements UserDetails {

    private int id;

    private String name;

    private String email;

    private String username;

    private String password;

    private int state;

    private int role;

    private String wechatOpenId;

    private String inviteCode;

    private int invitorId;

    private long tokens;

    private long chatCount;

    private long advancedChatCount;

    private long drawCount;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date updateTime;

    public static final int STATE_NORMAL = 1;
    public static final int STATE_DISABLED = 2;

    // 超级管理员
    public static final int ROLE_SUPER = 1;

    // 普通管理员
    public static final int ROLE_MANAGER = 2;

    // 普通会员
    public static final int ROLE_MEMBER = 10;

    // 一级VIP
    public static final int ROLE_VIP1 = 100;

    // 二级VIP
    public static final int ROLE_VIP2 = 110;

    // 三级VIP
    public static final int ROLE_VIP3 = 120;

    private List<BalanceEntity> balances;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new ArrayList<>();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return state == STATE_NORMAL;
    }

    @Override
    public UserEntity clone() {
        UserEntity userEntity = new UserEntity();
        userEntity.setId(id);
        userEntity.setName(name);
        userEntity.setEmail(email);
        userEntity.setUsername(username);
        userEntity.setRole(role);
        userEntity.setState(state);
        userEntity.setTokens(tokens);
        userEntity.setChatCount(chatCount);
        userEntity.setAdvancedChatCount(advancedChatCount);
        userEntity.setDrawCount(drawCount);
        userEntity.setCreateTime(createTime);
        userEntity.setUpdateTime(updateTime);
        userEntity.setPassword(null);
        userEntity.setInvitorId(invitorId);
        userEntity.setInviteCode(inviteCode);
        userEntity.setWechatOpenId(wechatOpenId);
        return userEntity;
    }
}
